//
//  ColorUtil.m
//  GTT_IOS
//
//  Created by allen.huang on 13-8-8.
//  Copyright (c) 2013年 allen.huang. All rights reserved.
//

#import "ColorUtil.h"

@implementation ColorUtil

+ (UIColor*)grayColor{
    return [UIColor colorWithRed:73.0/255 green:166.0/255 blue:51.0/255 alpha:1];
}

+ (UIColor*)redColor{
    return [UIColor colorWithRed:217.0/255 green:94.0/255 blue:64.0/255 alpha:1];
}

+ (UIColor*)skyBlueColor{//背景
    return [UIColor colorWithRed:230.0/255 green:237.0/255 blue:1 alpha:1];
}

+ (UIColor*)skyBlueColor1{//边框
    return [UIColor colorWithRed:200.0/255 green:200.0/255 blue:1 alpha:1];
}

+ (UIColor*)skyBlueColor2{//字体
    return [UIColor colorWithRed:0.0/255 green:51.0/255 blue:102.0/255 alpha:1];
}

+ (UIColor*)greenColor{
    return [UIColor colorWithRed:0.0 green:190.0/255 blue:10.0/255 alpha:1];
}

+ (UIColor*)greenBtnColor{
    return [ColorUtil colorWithHexadecimal:@"#00a964"];
}

+ (NSString *) getColorFromIndex:(NSInteger)COLOR_INDEX
{
    NSString *hexadecimal_16 = nil;
    switch (COLOR_INDEX) {
        case COLOR_1:
            return @"#653310";
            break;
        case COLOR_2:
            return @"#ecebeb";
            break;
        case COLOR_3:
            return @"#2f2e2e";
            break;
        case COLOR_4:
            return @"#adadad";
            break;
        case COLOR_5:
            return @"#ffffff";
            break;
        case COLOR_6:
            return @"#d6d6d6";
            break;
        case COLOR_7:
            return @"#f6f6f6";
            break;
        case COLOR_8:
            return @"#d4d3d3";
            break;
        case COLOR_9:
            return @"#f5f4f4";
            break;
        case COLOR_10:
            return @"#e6e6e6";
            break;
        case COLOR_11:
            return @"#74c401";
            break;
        case COLOR_12:
            return @"#d26e2e";
            break;
        case COLOR_13:
            return @"#b3aba8";
            break;
        case COLOR_14:
            return @"#00bda0";
            break;
        case COLOR_15:
            return @"#ee4017";
            break;
        case COLOR_16:
            return @"#ffefdf";
            break;
        case COLOR_17:
            return @"#fec9be";
            break;
        case COLOR_18:
            return @"#eb6004";
            break;
        case COLOR_19:
            return @"#959595";
            break;
        case COLOR_20:
            return @"#f92136";
            break;
        case COLOR_21:
            return @"#7e00a9";
            break;
        case COLOR_22:
            return @"#00d1fa";
            break;
        case COLOR_23:
            return @"#ffb202";
            break;
        case COLOR_24:
            return @"#e84c27";
            break;
        case COLOR_25:
            return @"#0caf0c";
            break;
        case COLOR_26:
            return @"#cf2c58";
            break;
        case COLOR_27:
            return @"#3758a3";
            break;
        case COLOR_28:
            return @"#6a6a6a";
            break;
        case COLOR_29:
            return @"#06ba7d";
            break;
        case COLOR_30:
            return @"#057bd6";
            break;
            
        default:
            break;
    }
    return hexadecimal_16;
}

+ (UIColor*)greenColor1{//背景
    return [UIColor colorWithRed:204.0/255 green:255.0/255 blue:204.0/255 alpha:1];
}
+ (UIColor*)greenColor2{//边框
    return [UIColor colorWithRed:154.0/255 green:255.0/255 blue:204.0/255 alpha:1];
}
+ (UIColor*)greenColor3{//字体
    return [UIColor colorWithRed:153.0/255  green:153.0/255 blue:153.0/255 alpha:1];
}
+ (UIColor*)transparent{
    return [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
}
+ (UIColor*)translucent{
    return [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5];
}
+ (UIColor*)bgColor{//背景
    return [ColorUtil colorWithHexadecimal:@"#f7f7f7"];
}
+ (UIColor*)colorWithRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue alpha:(NSInteger)alpha{
    return [UIColor colorWithRed:red*1.0/255 green:green*1.0/255 blue:blue*1.0/255 alpha:alpha*1.0/255];
}
+ (UIColor*)colorWithHexadecimal:(NSString*)hexadecimal_16{
    NSString *cString = [[hexadecimal_16 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if([cString length]==3){
        NSString *newString=[cString substringWithRange:NSMakeRange(0, 1)];
        [newString stringByAppendingString:[cString substringWithRange:NSMakeRange(0, 1)]];
        [newString stringByAppendingString:[cString substringWithRange:NSMakeRange(1, 1)]];
        [newString stringByAppendingString:[cString substringWithRange:NSMakeRange(1, 1)]];
        [newString stringByAppendingString:[cString substringWithRange:NSMakeRange(2, 1)]];
        [newString stringByAppendingString:[cString substringWithRange:NSMakeRange(2, 1)]];
        cString=newString;
    }
    
    if ([cString length] != 6 && [cString length] != 8)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    unsigned int a=255;
    if([cString length] == 8){
        //a
        range.location = 6;
        NSString *aString = [cString substringWithRange:range];
        [[NSScanner scannerWithString:aString] scanHexInt:&a];
    }
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:((float) a / 255.0f)];
}
@end
